package com.zhuss.core.permission;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.core.permission.CreatePermissionBo;
import com.zhuss.bean.bo.core.permission.DeletePermissionBo;
import com.zhuss.bean.bo.core.permission.PermissionResourceBindBo;
import com.zhuss.bean.bo.core.permission.PermissionRoleBindBo;
import com.zhuss.bean.bo.core.permission.UpdatePermissionBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.AabException;

/**
 * 权限点操作service（基本操作）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("permissionOperateService")
public class PermissionOperateService implements OperateService<Object, Object> {
	
	@Autowired
	@Qualifier("permissionCreate")
	private Processor<Object, CreatePermissionBo> permissionCreate;
	
	@Autowired
	@Qualifier("permissionUpdate")
	private Processor<Object, UpdatePermissionBo> permissionUpdate;
	
	
	@Autowired
	@Qualifier("permissionDelete")
	private Processor<Object, DeletePermissionBo> permissionDelete;
	
	@Autowired
	@Qualifier("permissionResourceBind")
	private Processor<Object, PermissionResourceBindBo> permissionResourceBind;
	
	@Autowired
	@Qualifier("permissionRoleBind")
	private Processor<Object, PermissionRoleBindBo> permissionRoleBind;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Object create(Object param) throws AabException {
		
		CreatePermissionBo bo = (CreatePermissionBo) param;
		
		Object permissionId = permissionCreate.process(bo);
		
		return permissionId;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws AabException {
    	
		UpdatePermissionBo bo = (UpdatePermissionBo) param;
		
		permissionUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws AabException {
		
		DeletePermissionBo bo = (DeletePermissionBo) param;
		
		permissionDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 给权限绑定菜单资源
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void permissionResourceBind(Object param) throws AabException {
		
		PermissionResourceBindBo bo = (PermissionResourceBindBo) param;
		
		permissionResourceBind.process(bo);
		
		return null;
	}
	
	
	/**
	 * 给权限绑定角色
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void permissionRoleBind(Object param) throws AabException {
		
		PermissionRoleBindBo bo = (PermissionRoleBindBo) param;
		
		permissionRoleBind.process(bo);
		
		return null;
	}
	
}

